package com.ruoyi.print.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.print.domain.PhotoTask;
import com.ruoyi.print.service.IPhotoTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.print.domain.SinglePhoto;

/**
 * 照片打印任务Controller
 * 
 * @author ruoyi
 * @date 2025-08-03
 */
@RestController
@RequestMapping("/print/print")
public class PhotoTaskController extends BaseController
{
    @Autowired
    private IPhotoTaskService photoTaskService;

    /**
     * 查询照片打印任务列表
     */
    @PreAuthorize("@ss.hasPermi('print:print:list')")
    @GetMapping("/list")
    public TableDataInfo list(PhotoTask photoTask)
    {
        startPage();
        List<PhotoTask> list = photoTaskService.selectPhotoTaskList(photoTask);
        return getDataTable(list);
    }

    /**
     * 导出照片打印任务列表
     */
    @PreAuthorize("@ss.hasPermi('print:print:export')")
    @Log(title = "照片打印任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PhotoTask photoTask)
    {
        List<PhotoTask> list = photoTaskService.selectPhotoTaskList(photoTask);
        ExcelUtil<PhotoTask> util = new ExcelUtil<PhotoTask>(PhotoTask.class);
        util.exportExcel(response, list, "照片打印任务数据");
    }

    /**
     * 获取照片打印任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('print:print:query')")
    @GetMapping(value = "/{photoTaskId}")
    public AjaxResult getInfo(@PathVariable("photoTaskId") Long photoTaskId)
    {
        return success(photoTaskService.selectPhotoTaskByPhotoTaskId(photoTaskId));
    }

    /**
     * 新增照片打印任务
     */
    @PreAuthorize("@ss.hasPermi('print:print:add')")
    @Log(title = "照片打印任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PhotoTask photoTask)
    {
        return toAjax(photoTaskService.insertPhotoTask(photoTask));
    }

    /**
     * 修改照片打印任务
     */
    @PreAuthorize("@ss.hasPermi('print:print:edit')")
    @Log(title = "照片打印任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PhotoTask photoTask)
    {
        return toAjax(photoTaskService.updatePhotoTask(photoTask));
    }

    /**
     * 删除照片打印任务
     */
    @PreAuthorize("@ss.hasPermi('print:print:remove')")
    @Log(title = "照片打印任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{photoTaskIds}")
    public AjaxResult remove(@PathVariable Long[] photoTaskIds)
    {
        return toAjax(photoTaskService.deletePhotoTaskByPhotoTaskIds(photoTaskIds));
    }

    /**
     * 根据任务ID获取该任务下的所有照片
     */
    @PreAuthorize("@ss.hasPermi('print:print:query')")
    @GetMapping("/{photoTaskId}/photos")
    public AjaxResult getPhotosByTaskId(@PathVariable("photoTaskId") Long photoTaskId)
    {
        return success(photoTaskService.selectSinglePhotosByPhotoTaskId(photoTaskId));
    }

    /**
     * 批量添加照片到任务
     */
    @PreAuthorize("@ss.hasPermi('print:print:add')")
    @Log(title = "照片打印任务", businessType = BusinessType.INSERT)
    @PostMapping("/{photoTaskId}/photos")
    public AjaxResult addPhotosToTask(@PathVariable("photoTaskId") Long photoTaskId, @RequestBody List<SinglePhoto> photos)
    {
        return toAjax(photoTaskService.insertSinglePhotos(photoTaskId, photos));
    }
}
